#ifndef __SOFTPWMITEM_H__
#define __SOFTPWMITEM_H__

#include "plat/nonecopyable.h"
#include "soc/soc_timer.h"
#include "soc/soc_gpio.h"


/// @brief PWM 生成器
///        可以生成互补的二路PWM
class SoftPwmItem : public NoneCopyable
{
public:
    enum class PointPostion
    {
        None = -1,
        P1 = 0,
        P2
    };

public:
    explicit SoftPwmItem();
    virtual ~SoftPwmItem();

public:
    void AttachGpio(const GpioPortPin &gpio, const GpioPortPin &gpioN = GpioPortPin::None());
    void DettachGpio();

    void Update();

    bool Check();
    void Begin();
    void End();
    int Next();

    //pwm finished point
    inline bool IsFinishedPoint(){return LastPoint == PointPostion::P2;}

public:
    GpioPortPin Port;
    GpioPortPin PortN;

    bool IsReverse = false;
    uint8_t NormalValue = 0;
    bool IsSameWhenNormal = true; //normal下，二个通道是否一样
    
    int Period = 0;
    uint8_t Duty = 0;  //[0-100]

    //计算值
    int CalcT1 = 0; //计算后的us
    int CalcT2 = 0; //计算后的us
    bool IsFullOutMode = false;

    bool IsRunning = false;
    uint8_t CurrentValue = 0;
    uint8_t CurrentValueN = 0;
    PointPostion LastPoint = PointPostion::None;  //最后一次是在PWM的哪个点 [----P1____P2-----P1_____P2-----] 
};

#endif // __SOFTPWMITEM_H__
